﻿<!DOCTYPE html>
<html>
<!-- 安全管理师培训管理 -->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        body {
            padding-bottom: 10px;
        }

        .vue-treeselect_style .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }
    </style>
</head>

<body>
    <div id="app" class="popupW100" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
                 size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini vue-treeselect_style">
                        <el-form-item prop="personInCharge">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{"管理师"+mark.m}}
                                </template>
                                <tree-department-staff-single slot="suffix" v-model="Form.nameId" style="line-height:28px;"></tree-department-staff-single>

                            </el-input>
                            <span class="iputLineMust" v-if="!Form.nameId">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        {{"公司"+mark.m}}
                                    </template>
                                    <el-select @visible-change="visibleChange" v-model="Form.createFactory" slot="suffix" placeholder="请选择">
                                        <el-option v-for="item in createFactory" :label="item.value" :value="item.key"></el-option>
                                    </el-select>
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{SafetyManagerTraining.type+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.type" slot="suffix"
                                           :placeholder="SafetyManagerTraining.type">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option v-for="item in type" :label="item.value" :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" :offset="2">
                    <el-col>
                        <div class="elst-select-mini vue-treeselect_style">
                            <el-form-item>
                                <el-input type="text" v-model="Form.trainedNumber" autocomplete="off" size="mini">
                                    <template slot="prepend">
                                        {{"年度培训目标"+mark.m}}
                                    </template>
                                </el-input>
                                <span class="iputLineMust" v-if="!Form.trainedNumber">
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                    <el-button type="primary" v-if="isshow" @click="userdelete">删除</el-button>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog title="安全管理师培训管理人员添加" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%"
            height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        var app = new Vue({
            el: '#app',
            data: {
                isshow: false,
                //表单内容
                ListItem: ListItem,
                options: [],
                createFactory: [],
                type: [],
                formInline: {
                    model: { name: '', type: '' },
                    offset: 0,
                    limit: 10
                },
                id: '',
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    name: '',
                    type: '',
                    trainedNumber: 0,
                },
                //表单验证
                rules: {

                }

            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            if (mythis.Form.nameId == null || mythis.Form.nameId == "" || mythis.Form.nameId == undefined) {
                                alert("请选择用户");
                                return false;
                            }
                            if (mythis.Form.type == null || mythis.Form.type == "" || mythis.Form.type == undefined) {
                                alert("请选择管理师类型");
                                return false;
                            }
                            if (mythis.Form.createFactory == null || mythis.Form.createFactory == "" || mythis.Form.createFactory == undefined) {
                                alert("请选择公司");
                                return false;
                            }
                            if (mythis.Form.name == null || mythis.Form.name == "" || mythis.Form.name == undefined) {
                                var list = mythis.options;
                                //for (var i = 0; i < list.length; i++) {
                                //    if (list[i].id == mythis.Form.nameId) {
                                //        mythis.Form.name = list[i].label;
                                //    }
                                //}
                                mythis.setname(mythis, list);
                            }
                            

                            
                            if (parseInt(mythis.Form.trainedNumber) >= 0) {
                                onSubmitForm(this, '/api/ZB_SafetyTrainer/Save', mythis.Form);
                            } else {
                                alert("年度培训目标填写不正确");
                                return false;
                            }
                            
                        } else {
                            //验证失败

                            return false;
                        }
                    });

                },
                //初始管理师类型
                getTypeList: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/CBS_DayCheckItem/CBSsglbGetList', { model: { category: 'zbglspx' }, offset: 0, limit: 100 }, function (response) {
                        mythis.type = response.data;

                        //console.log(response.data.pageData);
                    }, false);
                },
                getData: function () {
                    if (this.id == null || this.id == "" || this.id == undefined || this.id == "undefined" ) {
                        this.id = "";
                        this.isshow = false;
                    } else {
                        getData(this, '/api/ZB_SafetyTrainer/get?id=' + this.id);
                        this.isshow = true;
                    }
                },
                getUsers: function () {
                    var mythis = this;
                    myAjax("Get", null, "/api/Tree/GetTreeDepartmentStaff", null, function (response) {
                        var ajaxModel = response.data;
                        mythis.options = PersonMenuHelper(ajaxModel, guidEmpty);
                    }, false);
                },
                //工厂
                getdData: function () {
                    var url = "/api/WebPageInitial/FactoryListAll";
                    var app = this;
                    myAjax("get", this, url, null, function (response) {
                        app.createFactory = response.data;

                    }, false);

                    //if (this.data && this.data.length > 0)
                    //this.model = this.data[0].key;
                },
                setname: function (mythis,list) {
                    for (var i = 0; i < list.length; i++) {
                        if (list[i].id == mythis.Form.nameId) {
                            mythis.Form.name = list[i].label;
                        }
                        if (list[i].children == null || list[i].children == undefined || list[i].children.length == undefined) { } else {
                            if (list[i].children.length > 0) {
                                mythis.setname(mythis, list[i].children);
                            }
                        }
                    }

                },
                userdelete: function () {
                    var mythis = this;
                    this.$confirm(' 是否确认继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        
                        myAjax("post", this, "/api/ZB_SafetyTrainer/DeleteMuti", [mythis.id], function (response) {
                            mythis.GetPageData(1);
                            mythis.ListItem.currentPage = 1;
                            showMessage(msg.OperatingOk, "success");
                            parent.app.ListItem.dialogVisible = false;
                        });

                    }).catch(function () {
                        showMessage("已取消删除!");
                    });
                },
                //Dialog展示
                // SafetyManagerTrainingInput: function (val, id) { DialogShow(this, val, "GasDetectionManagementInputUserPerson.html", id); },
            },
            mounted: function () {
                this.getdData();
                this.getUsers();
                this.getTypeList();
                this.id = getUrlParam("id");
                this.getData();
                //初始化数据
                // this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);
                //this.type = getDicData('50');
            },

        });
        //下拉树数据格式化
        function menuHelperX(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelperX(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>